package com.huaixia18.systemnotice.service;

import com.huaixia18.systemnotice.domain.EventRemind;
import com.huaixia18.systemnotice.mapper.EventRemindMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
public class EventRemindService {

    @Autowired
    private EventRemindMapper eventRemindMapper;

    /**
     * 处理用户行为产生的事件提醒
     * @param remind 事件提醒对象
     */
    public void handleEventRemind(EventRemind remind) {
        eventRemindMapper.insert(remind);
    }

    /**
     * 聚合事件提醒（这里简单示例点赞消息的聚合）
     * @param recipientId 接收者ID
     * @return 聚合后的事件提醒列表
     */
    public Map<String, List<EventRemind>> aggregateEventReminds(Long recipientId) {
        List<EventRemind> reminds = eventRemindMapper.findByRecipientIdAndAction(recipientId, "点赞");
        return reminds.stream().collect(Collectors.groupingBy(remind -> remind.getSourceId() + "_" + remind.getSourceType()));
    }
}
